#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>

#define SHOW_LIMIT(name) show_limit(#name, name)

static void  show_limit(const char *resource_string, int resource_code);

int main(int argc, char *argv[]) {
    SHOW_LIMIT(RLIMIT_CORE);
    SHOW_LIMIT(RLIMIT_AS);
    SHOW_LIMIT(RLIMIT_CPU);
    SHOW_LIMIT(RLIMIT_DATA);
    SHOW_LIMIT(RLIMIT_FSIZE);
    SHOW_LIMIT(RLIMIT_LOCKS);
    SHOW_LIMIT(RLIMIT_MEMLOCK);
    SHOW_LIMIT(RLIMIT_NOFILE);
    SHOW_LIMIT(RLIMIT_NPROC);
    SHOW_LIMIT(RLIMIT_RSS);
    SHOW_LIMIT(RLIMIT_STACK);
#ifdef RLIMIT_VMEM
    SHOW_LIMIT(RLIMIT_VMEM);
#endif

    return EXIT_SUCCESS;
}

static void show_limit(const char *rstr, int res) {
    struct rlimit limit;
    if (getrlimit(res, &limit) < 0) {
        printf("error getrlimit\n");
        exit(EXIT_FAILURE);
    }
    printf("currunt limit(%-15s): %ld\n", rstr, limit.rlim_cur);
    RLIM_INFINITY == -1 ?
        printf("hard limit   (%-15s): infinity\n", rstr) :
        printf("hard limit   (%-15s): %ld\n", rstr, limit.rlim_max);
    printf("\n");
}
